package com.sg.service.impl;

import com.sg.bean.Join;
import com.sg.dao.JoinDao;
import com.sg.service.JoinService;
import com.sg.vo.JobChartInfo;
import com.sg.vo.JoinVO;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author fyp
 * 招聘信息业务逻辑实现类
 */
@Service
public class JoinServiceImpl implements JoinService {
    Logger logger=Logger.getLogger(JoinServiceImpl.class);
    @Autowired
    JoinDao joinDao;
    @Override
    public List<JoinVO> findAll() {
        return joinDao.findAll();
    }

    @Override
    public Join findById(int joinId) {
        return joinDao.findById(joinId);
    }

    @Override
    public boolean add(Join join) {
        //当前的时间
        join.setJoinCreateTime(new Timestamp(System.currentTimeMillis()));
        return joinDao.add(join)>0?true:false;
    }

    @Override
    public boolean delete(int joinId) {
        return joinDao.delete(joinId)>0?true:false;
    }
    public boolean update(int joinId) {
        return joinDao.update(joinId)>0?true:false;
    }

    @Override
    public List<JoinVO> findPersonList(int jpId) {
        return joinDao.findPersonList(jpId);
    }
    @Override
    public List<JobChartInfo> findStatPie() {
        return joinDao.findStat();
    }

    @Override
    public Map<String, List> findStatBar() {
        Map<String, List> map = new HashMap<>();
        List<JobChartInfo> list = joinDao.findStat();
        List<String> names = new ArrayList<>();
        List<Integer> values = new ArrayList<>();
        for (JobChartInfo info : list){
            names.add(info.getName());
            values.add(info.getValue());
        }
        map.put("names",names);
        map.put("values",values);
        return map;
    }
}
